<%--
 *  File:    ProdCptEdit.jsp
 *  @Author: KevinFan
 *  Date:    2012/09/28
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<%
  //init param
  Category cat = Category.getInstance("jsp.ProdCptEdit");
  String privilegeCode = "10300";
  String strModuleName = "PCM";
  String contextPath = request.getContextPath();
%>

<%
  String strIsNew=(String)request.getParameter("isnew");
  //System.out.println((String)request.getParameter("isnew"));
  //Enumeration en = request.getParameterNames();
  //while(en.hasMoreElements())
  // System.out.println("a "+en.nextElement());
  if(strIsNew==null)
    strIsNew="";
%>
<%
  HashMap userInfo = (HashMap)session.getAttribute("userinfo");

%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>

<html>
<head>
<title>ProdEditMain</title>
<PageFlow:CheckPageFlow pageName="p_prodcptedit"/>
<%@ include file="/inc/InitEdit.inc" %>
<%
  String op = null;
  op = (String)pageContext.getAttribute("op");
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%= contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%= contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%= contextPath%>/js/ScriptLib.js"></script>
<iframe name="reloadHandler" style="display:none" ></iframe>
<script language="JavaScript">
function page_done()
{
	//checkprice();
  if(!checkForm(document.cform))return;
  document.cform.actionname.value = "save";
  document.cform.target="_parent";
  isRunning = true;
  document.cform.submit();
}

var popwindow;

function page_setcategory(categorycode)
{
	 cform.categoryname.value ="";
     cform.categoryid.value ="";
	 
     if(categorycode!=null&&categorycode!="")   cform.categorycode.value =categorycode;

     if(cform.categorycode.value==""){
       cform.categoryname.value ="";
       return;
     }else{
       cform.schema.value="ovcategory";
       cform.qlname.value="selectchildbycode";
       page_handleRequest('<%=contextPath%>',cform);
     }
}

function page_handleResponse()
{
	if(getResponseData("categoryid")!=null&&getResponseData("categoryid")!="")
    {
        cform.categoryid.value = getResponseData("categoryid");
        cform.categorycode.value = getResponseData("categorycode");
        cform.categoryname.value = getResponseData("categoryname");
    }
}

function page_selectProd() {

		var status = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
		var url = "<%= contextPath%>/phap/phap.datp/masterdata/kdm/ProductSelect.jsp?<%= OvalTools.randomURL() %>";
		
		if (typeof popwindow != 'undefined') popwindow.close();
		popwindow = window.open(url, "newwindow1", status);
}

function page_selectCategory() {
		var status = "height=400, width=500,top=100,left=300,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
		var url = "CategorySelectPop.jsp?<%= OvalTools.randomURL() %>";
		if (typeof popwindow != 'undefined') popwindow.close();
		popwindow = window.open(url, "newwindow1", status);
}

function page_setproduct(id,umcode,prodcode,prodname)
{
    document.cform.productid.value = id;
    document.cform.prodcode.value=prodcode;
    document.cform.prodname.value=prodname;
}

function page_checkProdCode(){
	var prodcode = document.cform.prodcode.value;
	
	document.cform.prodname.value = "";
	document.cform.productid.value = "";
	
	if(isEmpty(prodcode)) return;
	
	document.cform.prodcode.value = "";
	
	var  datahandler = new  DataHandler() ;
	datahandler.add_params("prodcode" , prodcode,"String");
	datahandler.getResult("prodname","document.cform.prodname");
	datahandler.getResult("prodcode","document.cform.prodcode"); 
	datahandler.getResult("prodid","document.cform.productid");
	datahandler.add_job("j_getproduct") ;
	datahandler.runDataHandler();
}
</script>
</head>
<body>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<form name="cform" method="post" action="../../../Dispatcher">
      <input type="hidden" name="pagename" value="p_prodcptedit">
      <input type="hidden" name="actionname">
      <input type="hidden" name="schema" value="">
      <input type="hidden" name="qlname" value="">
	  <custom:hidden name="prodcptinfo" property="prodcptid"/>
        <tr>
          <td>
        <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">
          <tr>
            <td colspan="4" class="deepblue-left"> <img src="../../../images/<%= strLanguageCode %>/quote.gif">
              <%= label.getLabelName("L_BasicInfo") + label.getLabelName("L_Colon") %> </td>
          </tr>
          <%
            String strReadOnly="readonly";
            String strIsNull="Y";
            if(strIsNew.equals("Y"))
            {
              strReadOnly="";
              strIsNull="N";
            }
          %>
          <tr>
            <td class="need" width="120"><%= label.getLabelName("L_ProdCtpCode") + label.getLabelName("L_Colon") %></td>
            <td  >
              <input type="text" isnull="<%=JspHelper.filterNull(strIsNull)%>" value="<custom:write name="prodcptinfo" property="prodcptcode"/>" <%=JspHelper.filterNull(strReadOnly)%> label="<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_ProdCode",false))%>" size="20"  name="prodcptcode"/>
            </td>
			<td class="td-text"><%= label.getLabelName("L_Product") + label.getLabelName("L_Colon") %></td>
			<td>
	           	<custom:text name="prodcptinfo" property="prodcode" onchange="javascript:page_checkProdCode();" size="20"/>
	           	<a onclick="javascript:page_selectProd();"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
	           	<custom:text name="prodcptinfo" property="prodname" size="40"/>
	           	<input type="hidden" name="productid"/>
            </td>
          </tr>
          <tr>
            <td class="need"><%= label.getLabelName("L_ProdCtpName") + label.getLabelName("L_Colon") %></td>
            <td>
              <custom:text name="prodcptinfo" property="prodcptname" size="42" command="notnull" label="L_ProductName"/>
            </td>
            <td class="td-text" width="106" ><%= label.getLabelName("L_Category") + label.getLabelName("L_Colon") %></td>
            <td>
				<custom:hidden property="categoryid" name="prodcptinfo" command="notnull" label="L_Category"/>
				<oval:text name="prodcptinfo" property="categorycode"  isnull="N"  size="20" onchange="page_setcategory()"  />
				<a onClick='page_selectCategory()'><img src="../../../images/<%= strLanguageCode %>/tree.gif" border="0"></a>
                <oval:text name="prodcptinfo" property="categoryname"  size="20" readonly="true"/>
            </td>
          </tr>          
          <tr>
            <td class="td-text"><%= label.getLabelName("L_Spec") + label.getLabelName("L_Colon") %></td>
            <td>
              <custom:text name="prodcptinfo" property="spec"/>
            </td>
            <td class="td-text"><%= label.getLabelName("L_UOM") + label.getLabelName("L_Colon") %></td>
            <td>
                <oval:select optionsName="allumcode" optionValueKey="umcode" optionInnerTextKey="umname" name="prodcptinfo" property="umcode" defaultValueCost="" defaultValue="-----"/>
            </td>
          </tr> 
          <tr>
			<td class="td-text"><%= label.getLabelName("L_Brand") + label.getLabelName("L_Colon") %></td>
            <td>
               <custom:select  optionsName="allbrands" optionValueKey="brandcode" optionInnerTextKey="brandname" name="prodcptinfo" property="brandcode" defaultValueCost="" defaultValue="-----"/>
            </td>
			<td class="td-text">&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
      </td>
    </tr>
</form>
<tr>
  <td class="summary_top"></td>
</tr>
<tr>
  <td class="td_center">
	<a onclick="page_done();"><custom:button type="1" label="L_Finish" imgsrc="save_btn.gif" border="0" style="width:60"/></a>
  </td>
</tr>
</table>
</body>
</html>